package com.ruif.client;

import java.sql.Connection;

import javax.swing.JOptionPane;

import com.ruif.dao.UserDAO;
import com.ruif.model.User;
import com.ruif.service.IUserService;
import com.ruif.util.DBUtil;
import com.ruif.util.StringUtil;

public class UserServiceImpl implements IUserService
{
    UserDAO userDao = new UserDAO();
    DBUtil db = new DBUtil();
    
    public User login(User user)
    {
        if (StringUtil.isEmpty(user.getName()))
        {
            JOptionPane.showMessageDialog(null, "用户名不能为空！");
            return null;
        }
        if (StringUtil.isEmpty(user.getPassword()))
        {
            JOptionPane.showMessageDialog(null, "用户密码不能为空！");
            return null;
        }
        Connection conn = null;
        try
        {
            conn = db.getConn();
            return userDao.login(conn, user);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                db.closeConn(conn);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        
        return null;
    }

}
